package com.bynk.bynk_demo.controller;

import com.bynk.bynk_demo.model.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;



@RequestMapping("/hello")
//@Controller
@RestController
//相当于是 @Controller 与 @ResponseBody 的组合注解，意味着当前控制层类中的所有方法返回的都是Json对象
public class HelloController {


    /*第一个springboot案例*/

    //返回hello
    @RequestMapping("/hello")
    @ResponseBody
    public String hello(){
        return "hello";
    }

    //返回静态文件

    //返回json

    /*
    Get传参
        url:http://localhost/hello?name=wwh
    */

    //url拼接+单参数
    @GetMapping("helloname")
    public String helloName(@RequestParam("name") String userName){
        return "hello"+userName;
    }

    @GetMapping("hellonamelist")
    public String helloName(@RequestParam("name") List<String> userName){
        return "hello"+userName.toString();
    }

    //url拼接+多参数
    //localhost/helloUser?userName=wwh&pwd=123456

    @GetMapping("hellouser")
    public User helloUser(String userName, String pwd){
        return new User();
    }
    //也可以直接拿类型接收,但必须与属性名对应
    @GetMapping("user")
    public User helloUser(User user){
        return user;
    }


    //跳转到页面的简单方案
    @GetMapping("getpage")
    public String helloName(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.sendRedirect("/html/login.html");
        return null;
    }

    @PostMapping("/login")
    public User login1(@RequestBody User user){
        return user;
    }

    @PostMapping("/login1")
    public String login1(@RequestBody Map map){
        System.out.println(map.values());

        return map.toString();

    }






}
